<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['extradata']=array();
$return['diy']=plugin('jy_quan')->plugin_setting('diy');
$basic=plugin('jy_quan')->plugin_setting('basic');
$basic['quan_desc']=$basic['quan_desc']?$basic['quan_desc']:'接龙商城，发布商品，社区群，微信群接龙！另外还有有拼团、预约、报名、二手信息、拼车、互动等信息的发布...';
if($_RQ['op']=='main'){
	$quanid = intval($_RQ['quanid']);
	$this->session('quanid',$quanid);
	$snsid = intval($_RQ['snsid']);
	$this->session('snsid',$snsid);
	$fromuser = intval($_RQ['fromuser']);
	$pcd_code = intval($_RQ['pcd_code']);
	$this->session('fromuser',$fromuser);
	$notice = intval($_RQ['notice']);
	$this->session('notice',$notice);
	if($pcd_code && !$snsid && !$notice){
		$return['pcd']=cfc('area')->get_pcd_array($pcd_code);
		$return['params']=array();
		$return['upsns']=true;
		exi($return);
	}
	if(!$quanid && $basic['issns'] && !$snsid  && !$notice){
		$return['params']=array();
		$return['upsns']=true;
		$return['pcd']=array();
		exi($return);
	}
	if($quanid){
		plugin('jy_quan')->add_member(0,intval($_RQ['fromuser']),0,$quanid);
		$return['likesnum']=pdo_getsum('jy_quan_item',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'mid'=>$quanid),'likes');
		$return['looksnum']=pdo_getsum('jy_quan_item',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'mid'=>$quanid),'looks');
		$return['jielinum']=pdo_count('jy_quan_item_jieli',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$quanid),'id');
		$return['fensnum']=pdo_count('jy_quan_userlog',array('uniacid'=>$_SESSION['uniacid'],'isfollow'=>1,'userid'=>$quanid),'id');
		$member = pdo_get('jy_quan_member',array('mid'=>$quanid,'uniacid'=>$_SESSION['uniacid']),array('logo','title','desc','pcd'));
		$return['quaninfo']=$member;
		$htmltitle = $member['title'];
		$share_desc = $member['desc'];
		$share_image = $member['logo'];
		$return['isfans']=pdo_getcolumn('jy_quan_userlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'userid'=>$quanid),'isfollow');
		//进入圈详情，记录访问者浏览信息
		$islook=pdo_get('jy_quan_quanlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'quanid'=>$quanid));
		if(empty($islook)){
			$insert=array(
				'uniacid'=>$_SESSION['uniacid'],
				'quanid'=>$quanid,
				'mid'=>$_SESSION['uid'],
				'createtime'=>TIMESTAMP
			);
			pdo_insert('jy_quan_quanlog',$insert);
		}else{
			pdo_update('jy_quan_quanlog',array('createtime'=>TIMESTAMP),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'quanid'=>$quanid));
		}
		$return['sharedata']=array(
			'title'=>$htmltitle,
			'desc'=>$share_desc,
			'link'=>custom_url('jy_weishopjie/index//quanid='.$quanid.'&current_plugin='.$_SESSION['current_plugin'],true),
			'imgUrl'=>ATTACHMENT_URL.$share_image,
		);
	}else{
		if($basic['issns']  && !$notice){
				//进入圈详情，记录访问者浏览信息
				$islook=pdo_get('jy_quan_quanlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'snsid'=>$snsid));
				if(empty($islook)){
					$insert=array(
						'uniacid'=>$_SESSION['uniacid'],
						'snsid'=>$snsid,
						'mid'=>$_SESSION['uid'],
						'createtime'=>TIMESTAMP
					);
					pdo_insert('jy_quan_quanlog',$insert);
				}else{
					pdo_update('jy_quan_quanlog',array('createtime'=>TIMESTAMP),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'snsid'=>$snsid));
				}
				plugin('jy_quan')->add_member(0,intval($_RQ['fromuser']),$snsid);
				$return['likesnum']=pdo_getsum('jy_quan_item',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'snsid'=>$snsid),'likes');
				$return['looksnum']=pdo_getsum('jy_quan_item',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'snsid'=>$snsid),'looks');
				$return['jielinum']=pdo_count('jy_quan_item_jieli',array('uniacid'=>$_SESSION['uniacid'],'snsid'=>$snsid),'id');
				$return['fensnum']=pdo_count('jy_quan_userlog',array('uniacid'=>$_SESSION['uniacid'],'snsid'=>$snsid,'isfollow'=>1),'id');
				$sns=pdo_get('jy_quan_sns',array('uniacid'=>$_SESSION['uniacid'],'id'=>$snsid));
				$sns['desc']=$basic['quan_desc'];
				$sns['logo']=$sns['logo']?$sns['logo']:$basic['logo'];
				$return['quaninfo']=$sns;
				$htmltitle = $sns['title'];
				$share_desc = $sns['desc'];
				$share_image = $sns['logo'];
				$return['isfans']=pdo_getcolumn('jy_quan_userlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'snsid'=>$snsid),'isfollow');
		}else{
			plugin('jy_quan')->add_member(0,intval($_RQ['fromuser']));
			$return['likesnum']=pdo_getsum('jy_quan_item',array('uniacid'=>$_SESSION['uniacid'],'status'=>1),'likes');
			$return['looksnum']=pdo_getsum('jy_quan_item',array('uniacid'=>$_SESSION['uniacid'],'status'=>1),'looks');
			$return['jielinum']=pdo_count('jy_quan_item_jieli',array('uniacid'=>$_SESSION['uniacid']),'id');
			$return['fensnum']=pdo_count('jy_quan_userlog',array('uniacid'=>$_SESSION['uniacid'],'snsid'=>$snsid,'isfollow'=>1),'id');
			$return['quaninfo']=array(
					'title'=>$basic['title'],
					'logo'=>$basic['logo'],
					'pcd'=>$basic['pcd'],
					'desc'=>$basic['desc'],
			);
			$htmltitle = $basic['title'];
			$share_desc = $basic['share_desc'];
			$share_image = $basic['share_image'];
			$return['isfans']=pdo_getcolumn('jy_quan_userlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'snsid'=>$snsid),'isfollow');
		}
		model('jy_quan/model')->upsnslook($snsid,$fromuser);
		if($return['quaninfo']['bossmid']){
			$return['quaninfo']['adds']=pdo_getcolumn('jy_quan_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$return['quaninfo']['bossmid']),'adds');
			$return['quaninfo']['adds']=json_decode($return['quaninfo']['adds'],true);
		}
		$return['sharedata']=array(
			'title'=>$htmltitle,
			'desc'=>$share_desc,
			'link'=>custom_url('jy_weishopjie/index//snsid='.$snsid.'&fromuser='.$_SESSION['uid'].'&current_plugin='.$_SESSION['current_plugin'],true),
			'imgUrl'=>ATTACHMENT_URL.$share_image,
		);
	}
	//获取流量IP
	$return['quaninfo']['mysum']=pdo_getsum('jy_quan_looklog',array('uniacid'=>$_SESSION['uniacid'],'fromuser'=>$_SESSION['uid']),'looks');
	if($return['quaninfo']['bossmid']){
		$return['isboss']=$return['quaninfo']['bossmid']==$_SESSION['uid']?1:0;
		$return['quaninfo']['bosssum']=pdo_getsum('jy_quan_looklog',array('uniacid'=>$_SESSION['uniacid'],'fromuser'=>$return['quaninfo']['bossmid']),'looks');	
	}
	//是否关注
	$return['isfollow']=pdo_getcolumn('core_fans',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'follow');
	$return['quanid']=$quanid;
	$return['snsid']=$snsid;
	$return['notices']=pdo_getall('core_account_article',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1'),'','id desc');
	$return['member']=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('createtime','credit1','credit2','mobile','avatar','nickname'));
	set_html('title',$htmltitle);
	$return['params']['page'] =1;
	exi($return);
}